<?php
require_once ('bookmark_sum.php');
do_html_header();
do_html_introduce();
do_html_register_form();
do_html_footer();
if (isset($_POST['username'])&&isset($_POST['password'])&&isset($_POST['username'])&&$_POST['username']!=""&&$_POST['password']!=""&&$_POST['email']!="") {
	$username=$_POST['username'];
	$password=$_POST['password'];
	$email=$_POST['email'];
	//空值和初始值和邮箱格式交由js验证
	//邮箱和用户名重复交由后台php实现
	if (db_connect()) {
		$conn=db_connect();
		$query_result=$conn->query("select * from user where username='".$username."' and email='".$email."' and password='".$password."'");
		if (@$query_result->num_rows==0||$query_result!=TRUE) {
			$query_result=$conn->query("insert into user values('".$username."','".$password."','".$email."')");
			//插入成功
			printf($query_result);
			if ($query_result) {
				echo '<script type="text/javascript">alert("注册成功，请登录！");location.href="./login.php"</script>';
			}
			else{
				echo '<script type="text/javascript">alert("注册失败，请重新注册！");location.href="./register.php"</script>';
			}
		}
		else {
		printf("Select return %d rows",$query_result->num_rows);
		echo '<script type="text/javascript">alert("该邮箱或用户名已经注册！");</script>';
		}
	}
}

?>